﻿#region Imports

using AopAlliance.Intercept;
using Common.Logging;

#endregion

namespace bGallery.Core.Aspects
{
	/// <summary>
	/// Advice for logging
	/// </summary>
	class LoggingAroundAdvice : IMethodInterceptor
	{
		#region Private fields
		
		private static readonly ILog log = LogManager.GetLogger("DAOLogger");

		#endregion

		#region Public methods

		/// <summary>
		/// Invokes adviced method
		/// </summary>
		/// <param name="invocation"></param>
		/// <returns></returns>
		public object Invoke(IMethodInvocation invocation)
		{
			log.Info("Invoking method: " + invocation.Method.Name + " on DAO: " + invocation.TargetType.Name);
			object returnValue = invocation.Proceed();
			log.Info(invocation.Method.Name + " method on DAO: " + invocation.TargetType.Name + " returned: " + returnValue);

			return returnValue;
		}

		#endregion
	}
}
